#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
typedef unsigned long long ull;
typedef pair<i64, i64> PII;
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define lowbit(x) (x & -x)
#define _for(i, a, b) for (int i = a, I_MAX = b; i <= I_MAX; i++)
#define _rep(i, a, b) for (int i = a, I_MIN = b; i >= I_MIN; i--)
#define KS                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int rx[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ry[8] = {1, 2, 2, 1, -1, -2, -2, -1};
const int MOD = 1e9 + 7;
const int INF = 0x3f3f;
const int N = 1e6 + 10;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445;

void print(__int128 x)
{
    if (!x)
        return;
    if (x < 0)
        putchar('-'), x = -x;
    print(x / 10);
    putchar(x % 10 + '0');
}

i64 gcd(i64 a, i64 b)
{
    return b ? gcd(b, a % b) : a;
}

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    return x * f;
}

i64 inv(i64 a, int b)
{
    i64 res = 1;
    while (b > 0)
    {
        if (b % 2 == 1)
        {
            res = (res * a);
        }
        a = (a * a);
        b >>= 1;
    }
    return res;
}

void solve()
{   
    int n;
    cin >> n;
    vector<int> a(n + 1);
    queue<int> q;
    vector<vector<int>> g(n + 1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if(a[i]) q.push(i);
    }
    
    while(!q.empty())
    {
        int pos = q.front();
        q.pop();
        int p_pos = pos - 1, f_pos = pos + 1, v = a[pos];
        if(p_pos > 0)
        {
            if(a[p_pos] == 0 && !g[p_pos].size())
            {
                g[p_pos].pb(v + 1);
                if(v - 1 > 0) g[p_pos].pb(v - 1);
            }
            else if(g[p_pos].size() && a[p_pos] == 0) 
            {
                for(auto it : g[p_pos])
                {
                    if(abs(it - v) == 1) a[p_pos] = it; 
                }
                if(a[p_pos] == 0) 
                {
                    cout << "-1";
                    return ;
                }
            }
            else
            {
                if(abs(a[p_pos] - v) != 1) 
                {
                    cout << "-1";
                    return ;
                }
            }
            if(g[p_pos].size() != 0)
            {
                q.push(p_pos);
            }
        }

        if(f_pos <= n)
        {
            if(a[f_pos] == 0 && !g[f_pos].size())
            {
                g[f_pos].pb(v + 1);
                if(v - 1 > 0) g[f_pos].pb(v - 1);
            }
            else if(g[f_pos].size() && a[f_pos] == 0) 
            {
                for(auto it : g[f_pos])
                {
                    if(abs(it - v) == 1) a[f_pos] = it; 
                }
                if(a[f_pos] == 0) 
                {
                    cout << "-1";
                    return ;
                }
            }
            else
            {
                if(abs(a[f_pos] - v) != 1) 
                {
                    cout << "-1";
                    return ;
                }
            }
            if(g[f_pos].size() != 0)
            {
                q.push(f_pos);
            }
        }
    }
    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}

int main()
{
    int t = 1;
    //cin>>t;
    mt19937 Rnd(time(0));
    while (t--)
    {
        solve();
    }
    return 0;
}